

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.PersonPlan;
import com.loong.loong.hik.service.PersonPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 陌生人员识别计划
 *
 * @author jinyiang
 * @date 2023-03-29 14:38:30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/personplan/strange" )
@Api(value = "strange", tags = "陌生人员识别计划管理")
public class PersonPlanStrangeController {

    private final  PersonPlanService personPlanService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param personPlan 陌生人员识别计划
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_personplan_view')" )
    public R getPersonPlanPage(Page page, PersonPlan personPlan) {
		personPlan.setFlag("2");
		return R.ok(personPlanService.findPage(page,personPlan));

    }


    /**
     * 通过id查询陌生人员识别计划
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_personplan_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(personPlanService.getById(id));
    }

    /**
     * 新增陌生人员识别计划
     * @param personPlan 陌生人员识别计划
     * @return R
     */
    @ApiOperation(value = "新增陌生人员识别计划", notes = "新增陌生人员识别计划")
    @SysLog("新增陌生人员识别计划" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_personplan_add')" )
    public R save(@RequestBody PersonPlan personPlan) {
		personPlan.setFlag("2");
        return R.ok(personPlanService.save(personPlan));
    }

    /**
     * 修改陌生人员识别计划
     * @param personPlan 陌生人员识别计划
     * @return R
     */
    @ApiOperation(value = "修改陌生人员识别计划", notes = "修改陌生人员识别计划")
    @SysLog("修改陌生人员识别计划" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_personplan_edit')" )
    public R updateById(@RequestBody PersonPlan personPlan) {
		personPlan.setFlag("2");
        return R.ok(personPlanService.updateById(personPlan));
    }

    /**
     * 通过id删除陌生人员识别计划
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除陌生人员识别计划", notes = "通过id删除陌生人员识别计划")
    @SysLog("通过id删除陌生人员识别计划" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_personplan_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(personPlanService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param personPlan 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_personplan_export')" )
    public List<PersonPlan> export(PersonPlan personPlan) {
		personPlan.setFlag("2");
    	return personPlanService.list(Wrappers.query(personPlan));
    }
}
